import * as Router from 'koa-router';
// import { IRouterContext } from '../core/IRouterContext';
import { IRouterContext } from 'koa-router';
import thhService from '../service/ThhService';
const motorCtr: Router = require('koa-router')();
motorCtr.prefix('/api')
import loginUtil from './../core/LoginUtils';

/*
 * 查询 测试用接口  
 */
motorCtr.get('/motor/testGetReturnInfo', async (ctx: IRouterContext, next: any) => {
    
    let result = await thhService.testGetReturnInfo();
    ctx.status = 200;
    ctx.body = result;
    await next()
})


/**
 * 退货单查询
 * 获取根据仓库关联的所有可查询的退货单列表菜单
 */
motorCtr.post('/motor/getReturnInfoList', async (ctx: IRouterContext, next: any) => {

    console.log('退换货接口进入__________________');
    let authorization :any = ctx.header.authorization;
    let rq: any = ctx.request
    let data = rq.body;
    let result = await thhService.getReturnInfoList(data,authorization);
    ctx.status = 200;
    ctx.body = result;
    await next()
})

//扫描退货单号 并根据仓库编号 查询退货单
motorCtr.post('/motor/getReturnInfo', async (ctx: IRouterContext, next: any) => {
    
    console.log('扫描退货单号 并根据仓库编号 查询退货单__________________');
    let authorization :any = ctx.header.authorization;
    let rq: any = ctx.request
    let data = rq.body;
    let result = await thhService.getReturnInfo(data,authorization);
    ctx.status = 200;
    ctx.body = result;
    await next()
})


/**
 * 销售退货单  待确认
 *  带取回 提交
 */
motorCtr.post('/motor/submitReturnInfo', async (ctx: IRouterContext, next: any) => {
    
    let authorization :any = ctx.header.authorization;
    console.log('authorization__________________',authorization);
    let rq: any = ctx.request
    let data = rq.body;
    let result = await thhService.submitReturnInfo(data,authorization);
    ctx.status = 200;
    ctx.body = result;

    await next()
})


/* *************************************************** */

motorCtr.post('/motor/getReturnInfoList2', async (ctx: IRouterContext, next: any) => {
    
    console.log('退换货接口进入__________________');
    let authorization :any = ctx.header.authorization;
    let rq: any = ctx.request
    let data = rq.body;
    let result = await thhService.getReturnInfoList2(data,authorization);
    ctx.status = 200;
    ctx.body = result;
    await next()
})

motorCtr.post('/motor/getReturnInfo2', async (ctx: IRouterContext, next: any) => {
    
    console.log('扫描退货单号 并根据仓库编号 查询退货单__________________');
    let authorization :any = ctx.header.authorization;
    let rq: any = ctx.request
    let data = rq.body;
    let result = await thhService.getReturnInfo2(data,authorization);
    ctx.status = 200;
    ctx.body = result;
    await next()
})




export default motorCtr;